package inesv.control;

import com.alibaba.fastjson.JSON;
import inesv.dto.User;
import inesv.dto.redisDto;
import inesv.service.userService;
import inesv.utils.SignUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class userControl {
	
	@Autowired
	redisDto redisDto;
	
	@Autowired
	userService service;

	@RequestMapping("/testSig")
	@ResponseBody
	public String testSig(HttpServletRequest request, @RequestBody User user) throws Exception {
		String sign = SignUtil.sign("123",JSON.toJSONString(user),null,null);
		if (!sign.equals(request.getHeader("sign"))){
			return "签名不正确";
		}
 		return user.toString();
	}

	@RequestMapping("/hello")
	@ResponseBody
	public String hello( ) {

		return "hello";
	}

	@RequestMapping("/user/getUser")
	@ResponseBody
	public User getUser(Long userNo) {
	 
 		return service.getUserById(userNo);
	}

}
